﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace intheweel
{
    public partial class addd : Form
    {
        public addd()
        {
            InitializeComponent();
        }

        public addd(string Title, string Author, string CreatedTime, int id)
        {
            InitializeComponent();
            this.id = id;
            textBox1.Text = Title;
            textBox2.Text = Author;
            textBox3.Text = CreatedTime;


        }
        private int id;
        private void button1_Click(object sender, EventArgs e)
        {
            if (id > 0)
            {
                var ki = textBox1.Text;
                var ji = textBox2.Text;
                var lk = textBox3.Text;

                var kki = string.Format("update Articles set Title = '{0}',Author = '{1}', CreatedTime = '{2}' where Id='{3}'", ki, ji, lk,id);
                var dbs = Dbhelper.Luoxuan(kki);
                if (dbs >= 0)
                {
                    MessageBox.Show("更新成功！");
                    this.DialogResult = DialogResult.Yes;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("更新失败!");
                }
            }
            else {
                var di = textBox1.Text;
                var wi = textBox2.Text;
                var ik = textBox3.Text;

                var ld = string.Format("insert into Articles(Title , Author , CreatedTime) values ('{0}','{1}','{2}')", di, wi, ik);
                var lld = Dbhelper.Luoxuan(ld);
                if (lld>=0) 
                {
                    MessageBox.Show("添加成功！");
                    this.DialogResult = DialogResult.Yes;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("添加失败!");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }
    }
}
